package com.zmn.oms.dubbo.impl.zmn.master.order;

import com.google.common.collect.Maps;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.oms.business.interfaces.work.OrderWorkProgrammeBService;
import com.zmn.oms.common.constant.AppConsts;
import com.zmn.oms.dubbo.dto.common.work.WorkProgrammeDRO;
import com.zmn.oms.dubbo.interfaces.zmn.master.order.MasterWorkProgrammeRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.model.entity.work.OrderWork;
import com.zmn.oms.services.interfaces.work.OrderWorkService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * 类描述：工单日程
 *
 * @author heciqi
 * @date 2021/11/01 14:15
 */
@Slf4j
@Service(loadbalance = "roundrobin", timeout = 5000, retries = 2, version = DubboConsts.INTERFACE_VERSION, validation = "false")
public class MasterWorkProgrammeRemoteServiceImpl implements MasterWorkProgrammeRemoteService {
	@Autowired
	OrderWorkProgrammeBService orderWorkProgrammeBService;

	@Autowired
	OrderWorkService orderWorkService;

	/**
	 * 获取工单日程
	 *
	 * @param workIds
	 * @return
	 */
	@Override
	public ResponseDTO<Map<Long,WorkProgrammeDRO>> listWorkProgramme(List<Long> workIds) {
		log.debug("MasterWorkProgrammeRemoteServiceImpl#getWorkProgramme入参:", workIds);

		List<OrderWork> orderWorks = orderWorkService.listOrderWorkByOrderIdList(workIds);
		Map<Long, WorkProgrammeDRO> map = Maps.newHashMapWithExpectedSize(workIds.size());
		orderWorks.forEach(e -> {
			String operateStr = orderWorkProgrammeBService.getOperateStr(e);
			Integer operateTextStatus = orderWorkProgrammeBService.getOperateTextStatus(e);
			WorkProgrammeDRO workProgrammeDRO = new WorkProgrammeDRO();
			workProgrammeDRO.setOperateStr(operateStr);
			workProgrammeDRO.setOperateTextStatus(operateTextStatus);
			workProgrammeDRO.setOperateText(AppConsts.getOperateText(operateTextStatus));
			map.put(e.getOrderId(), workProgrammeDRO);
		});
		log.debug("MasterWorkProgrammeRemoteServiceImpl#getWorkProgramme出参:", map);
		return ResponseDTO.success(map);
	}
}
